NodeMCU DHT
DHT Module
dht.read()
原型: dht.read(pin)
作用: 读取所有的DHT传感器,包括 DHT11, 21, 22, 33, 44温湿度传感器
参数: DHT传感器的针脚
返回值:
- status DHT的状态,有dht.OK, dht.ERROR_CHECKSUM, dht.ERROR_TIMEOUT三种值
- temp 传感器测得的温度
- humi 传感器测得的湿度
- temp_dec 温度小数部分
- humi_dec 湿度小数部分
例子:12345678910111213141516171819pin = 1status, temp, humi, temp_dec, humi_dec = dht.read(pin)if status == dht.OK then-- Integer firmware using this exampleprint(string.format("DHT Temperature:%d.%03d;Humidity:%d.%03d\r\n",math.floor(temp),temp_dec,math.floor(humi),humi_dec))-- Float firmware using this exampleprint("DHT Temperature:"..temp..";".."Humidity:"..humi)elseif status == dht.ERROR_CHECKSUM thenprint( "DHT Checksum error." )elseif status == dht.ERROR_TIMEOUT thenprint( "DHT timed out." )end